package com.member.web.controller.shop;

import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.enums.PaymentStatusEnum;
import com.member.common.enums.ProcessStatusEnum;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizWithdrawApply;
import com.member.shop.service.ISysBizWithdrawApplyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【提现申请】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-01-11
 **/
@RestController
@RequestMapping("/shop/withdraw")
public class SysBizWithdrawApplyController extends BaseController {
    @Resource
    private ISysBizWithdrawApplyService sysBizWithdrawApplyService;

    /**
     * 查询提现申请列表
     */
    @PreAuthorize("@ss.hasPermi('shop:withdraw:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizWithdrawApply sysBizWithdrawApply) {
        startPage();
        List<SysBizWithdrawApply> list = sysBizWithdrawApplyService.selectSysBizWithdrawApplyList(sysBizWithdrawApply);
        return getDataTable(list);
    }

    /**
     * 查询提现申请列表(统计)
     */
    @PreAuthorize("@ss.hasPermi('shop:withdraw:withdrawalCount')")
    @GetMapping("/withdrawalCount")
    public TableDataInfo withdrawalCount(SysBizWithdrawApply sysBizWithdrawApply) {
        startPage();
        List<SysBizWithdrawApply> list = sysBizWithdrawApplyService.withdrawalCount(sysBizWithdrawApply);
        return getDataTable(list);
    }

    /**
     * 导出提现申请列表
     */
    @PreAuthorize("@ss.hasPermi('shop:withdraw:export')")
    @Log(title = "提现申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizWithdrawApply sysBizWithdrawApply) {
        List<SysBizWithdrawApply> list = sysBizWithdrawApplyService.withdrawalCount(sysBizWithdrawApply);
        if (!list.isEmpty()) {
            for (SysBizWithdrawApply bizWithdrawApply : list) {
                bizWithdrawApply.setProcessStatusName(bizWithdrawApply.getProcessStatus().equals(ProcessStatusEnum.UN_PROCESS.getKey())?"待审核":bizWithdrawApply.getProcessStatus().equals(ProcessStatusEnum.PASS_PROCESS.getKey())?"审核通过":"审核驳回");
                bizWithdrawApply.setPaymentStatusName(bizWithdrawApply.getPaymentStatus().equals(PaymentStatusEnum.UNPAID.getKey())?"未打款":"已打款");
            }
        }
        ExcelUtil<SysBizWithdrawApply> util = new ExcelUtil<SysBizWithdrawApply>(SysBizWithdrawApply.class);
        util.exportExcel(response, list, "提现申请数据");
    }

    /**
     * 获取提现申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:withdraw:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizWithdrawApplyService.selectSysBizWithdrawApplyById(id));
    }

    /**
     * 新增提现申请
     */
    @PreAuthorize("@ss.hasPermi('shop:withdraw:add')")
    @Log(title = "提现申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizWithdrawApply sysBizWithdrawApply) {
        return toAjax(sysBizWithdrawApplyService.insertSysBizWithdrawApply(sysBizWithdrawApply));
    }

    /**
     * 删除提现申请
     */
    @PreAuthorize("@ss.hasPermi('shop:withdraw:remove')")
    @Log(title = "提现申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizWithdrawApplyService.deleteSysBizWithdrawApplyByIds(ids));
    }
}
